<?php require VIEW_ROOT.'/common/header.php'?>
<script type="text/javascript" src="./resource/images/finance/common_finance.js"></script>
<style>
.item{
	width:230px;
	float:left;
	margin:10px 10px 0 0;
	display:inline;
}
.item2{
	width:400px;
	float:left;
	margin:10px 10px 0 0;
	display:inline;
}
.money_num { cursor:pointer; }
.info_lite{
	width:50px;
	position:absolute;
	padding:3px;
	line-height:20px;
	display:none;
	
	background:#537DC1;
	color:#FFFFFF;
	border:#FFFFFF 1px solid;
}
.info_lite a { color:#FFFFFF; }

.weekday { font-weight:normal; font-size:10px; }
.day_sum { font-weight:bold; cursor:pointer; }

.note td { text-align:left; color:#999999; }
</style>
<script>
$(function() {
	// 点击加载当天的日志
	$('.item table th').toggle(
		function() {
			var obj = this;
			$.getJSON('./?m=note&a=get', {time:$(this).attr('name')}, function(data) {
				if(data == '') {
					$(obj).parent().after('<tr class="note"><td colspan="3"><div style="width:215px;">no note…</div></td></tr>');
				}
				var i;
				for(i in data) {
					$(obj).parent().after('<tr class="note"><td colspan="3"><div style="width:215px;">'+data[i].content+'</div></td></tr>');
				}
			});
		}, function() {
			$(this).parent().parent().find('.note').remove();
		}
	);
});
</script>

<div class="info_lite"></div>

<div class="info">
	[
	<a href="./?m=finance&a=pay_list&day=30">30天</a> /
	<a href="./?m=finance&a=pay_list&day=70">70天</a> /
	<a href="./?m=finance&a=pay_list&day=61,30">上月</a> /
	<a href="./?m=finance&a=pay_list&all">全部</a>
	] &nbsp;&nbsp;
	[
	<a href="#pay_add">添加</a>
	]
</div>

<!--start.每天数据-->
<?php foreach($v['daily_data'] as $row) {?>
	<div class="item">
		<table>
			<tr>
				<th colspan="3" name="<?php echo $row['info']['time']?>">
					<?php echo date('n月j日', $row['info']['time'])?>
					<span class="weekday">
						星期<?php echo library_common::get_week_name($row['info']['time']); ?>
						<?php echo date('N', $row['info']['time']) > 5 ? '~' : ''; ?>
					</span>
				</th>
			</tr>
		<!-- start.单条 -->
		<?php foreach($row['data'] as $row2) : ?>
			<tr class="item_one" sum="<?php echo $row2['amount']?>">
				<td width="20"><input type="checkbox" /></td>
				<td width="115"><div style="width:118px;"><?php echo $row2['pay_name']?></div></td>
				<td class="money_num">
					<?php echo library_common::money_num($row2['amount'])?>
					<span style="display:none;" class="item_edit">
						<a href="?m=finance&a=pay_edit&pay_id=<?php echo $row2['pay_id']?>">编辑</a> <br />
						<a href="?m=finance&a=pay_delete&pay_id=<?php echo $row2['pay_id']?>">删除</a> <br />
						<a href="#" onclick="$(this).parent().hide();return false;">关闭</a>
					</span>
				</td>
			</tr>
		<?php endforeach; ?>
		<!-- end.单条 -->
			<tr>
				<td colspan="3">
					 <span class="day_sum"><?php echo library_common::money_num($row['info']['sum'])?></span>
				</td>
			</tr>
		</table>
	</div>
<?php }//foreach?>
<!--end.每天数据-->

<!--start.clear-->
<div style="clear:both;height:0;"></div>
<!--end.clear-->

<a name="report"></a>
<div class="item2">
	<table>
		<tr>
			<th colspan="2">统计报表</th>
		</tr>
		<tr>
			<td width="150">统计天数</td>
			<td>
				<?php echo $pay_range['count']?>天
				(<?php echo date('Y.n.j', $v['pay_range']['min'])?> ~ <?php echo date('Y.n.j', $v['pay_range']['max'])?>)
			</td>
		</tr>
		<tr>
			<td>金额总计</td>
			<td><?php echo library_common::money_num($v['sum'])?></td>
		</tr>
		<tr>
			<td>总日均/月均</td>
			<td>
				<b style="background:#fbb;"><?php echo library_common::money_num(round($v['sum']/$v['pay_range']['count'], 2))?></b>
				/
				<?php echo library_common::money_num(round($v['sum']*30/$v['pay_range']['count'], 2))?>
			</td>
		</tr>
		<tr>
			<td>(去大额)总日均/月均</td>
			<td>
				<b style="background:#fbb;"><?php echo library_common::money_num(round($v['sum_limit']/$v['pay_range']['count'], 2))?></b>
				/
				<?php echo library_common::money_num(round($v['sum_limit']*30/$v['pay_range']['count'], 2)); ?>
			</td>
		</tr>
		<tr>
			<td>(大额)总日均/月均</td>
			<td>
				<?php echo library_common::money_num(round(($sum - $sum_limit) / $pay_range['count'], 2))?>
				/
				<?php echo library_common::money_num(round(($sum - $sum_limit) * 30 / $pay_range['count'], 2)); ?>
			</td>
		</tr>
		<tr>
			<td>近30天日均/总计</td>
			<td>
				<?php echo library_common::money_num(round($v['sum_30']/30, 2))?>
				/
				<?php echo library_common::money_num($v['sum_30'])?>
			</td>
		</tr>
		<tr>
			<td>(去大额)近30天日均/总计</td>
			<td>
				<b style="background:#fbb;"><?php echo library_common::money_num(round($v['sum_30_limit']/30, 2))?></b>
				/
				<?php echo library_common::money_num($v['sum_30_limit'])?>
			</td>
		</tr>
		<tr>
			<td>已选中总金额</td>
			<td><span class="checked_sum imp">0</span></td>
		</tr>
	</table>
</div>

<div class="item2">
<a name="pay_add"></a>
<form action="?m=finance&a=pay_add" method="post">
	<table>
		<tr>
			<th colspan="2">添加数据</th>
		</tr>
		<tr>
			<td>说明</td>
			<td class="frm"><input type="text" name="pay_name" value="" /></td>
		</tr>
		<tr>
			<td>数额</td>
			<td class="frm"><input type="text" name="amount" style="width:50px;" value="1" /></td>
		</tr>
		<tr>
			<td>时间</td>
			<td class="frm">
					<input type="text" name="create_time" id="create_time" value="<?php echo date('Y-n-j'); ?>" />
					<input type="button" onclick="create_time_add(1);" value="+" />
					<input type="button" onclick="create_time_add(-1);" value="-" />
					<script>
					function create_time_add(days) {
						var dom = document.getElementById('create_time');

						var dateStr = dom.value;
						var dateArr = dateStr.split('-');
						if (dateArr.length !== 3)
						{
							alert('日期格式错误！');
							return false;
						}
						var date = new Date(dateArr[0], dateArr[1] - 1, dateArr[2]);
						if (date == 'Invalid Date') {
							alert('日期格式错误！');
							return false;
						}
						var newDate = new Date(date.getTime() + 86400000 * days);
						var newDateString = newDate.getFullYear() + '-' + (newDate.getMonth() + 1) + '-' + newDate.getDate();

						dom.value = newDateString;
					}
					</script>
			</td>
		</tr>
		<tr>
			<td></td>
			<td class="frm"><input type="submit" value="提交" /></td>
		</tr>
	</table>
</form>
</div>

<div class="item2">
	<table>
		<tr>
			<th colspan="2">操作</th>
		</tr>
		<tr>
			<td width="100"></td>
			<td>
				<input type="button" onclick="Finance.toggleAll();" value="反选所有" />
			</td>
		</tr>
		<tr>
			<td width="100"></td>
			<td>
				<input type="button" onclick="$('.item_one').toggle();" value="只显示每日总额/显示所有" /> 	
			</td>
		</tr>
	</table>
</div>

<!--start.clear-->
<div style="clear:both;height:0;"></div>
<!--end.clear-->

<?php foreach ($notes as $row) {?>
<div class="info">
	<?php echo nl2br($row['content'])?>
	<a href="./?m=note&a=form_ajax& not_id=<?php echo $row['not_id']?>">[编辑]</a>
</div>
<?php }?>

<?php require VIEW_ROOT.'/common/footer.php'?>
